//Copyright 2010 Balazs Keri, Imre Keri
//
//This file is part of FireworksCreator.
//
//FireworksCreator is free software: you can redistribute it and/or modify
//it under the terms of the GNU General Public License as published by
//the Free Software Foundation, either version 3 of the License, or
//(at your option) any later version.
//
//FireworksCreator is distributed in the hope that it will be useful,
//but WITHOUT ANY WARRANTY; without even the implied warranty of
//MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
//GNU General Public License for more details.
//
//You should have received a copy of the GNU General Public License
//along with FireworksCreator.  If not, see <http://www.gnu.org/licenses/>.
//
#include "modeldataobjectadapter.h"
#include "modeldataobjectadapters.h"
//
//
const qint32 ModelDataObjectAdapter::data_version_1_qt_4_6 = 1;
//
ModelDataObjectAdapter::Initializer::Initializer()
{
   if (!ModelDataObjectAdapter::group_adapter)
      ModelDataObjectAdapter::group_adapter = new ModelGroupAdapter();
   if (!ModelDataObjectAdapter::shooter_adapter)
      ModelDataObjectAdapter::shooter_adapter = new ModelShooterAdapter();
   if (!ModelDataObjectAdapter::particle_template_adapter)
      ModelDataObjectAdapter::particle_template_adapter = new ModelParticleTemplateAdapter();
   if (!ModelDataObjectAdapter::emitter_template_adapter)
      ModelDataObjectAdapter::emitter_template_adapter = new ModelEmitterTemplateAdapter();
}
ModelDataObjectAdapter::Initializer::~Initializer()
{
   if (ModelDataObjectAdapter::group_adapter) {
      delete ModelDataObjectAdapter::group_adapter ; ModelDataObjectAdapter::group_adapter = 0;
   }
   if (ModelDataObjectAdapter::shooter_adapter) {
      delete ModelDataObjectAdapter::shooter_adapter ; ModelDataObjectAdapter::shooter_adapter = 0;
   }
   if (ModelDataObjectAdapter::particle_template_adapter) {
      delete ModelDataObjectAdapter::particle_template_adapter ; ModelDataObjectAdapter::particle_template_adapter = 0;
   }
   if (ModelDataObjectAdapter::emitter_template_adapter) {
      delete ModelDataObjectAdapter::emitter_template_adapter ; ModelDataObjectAdapter::emitter_template_adapter = 0;
   }
}
//
//
//
ModelGroupAdapter *ModelDataObjectAdapter::group_adapter = 0;
ModelShooterAdapter *ModelDataObjectAdapter::shooter_adapter = 0;
ModelParticleTemplateAdapter *ModelDataObjectAdapter::particle_template_adapter = 0;
ModelEmitterTemplateAdapter *ModelDataObjectAdapter::emitter_template_adapter = 0;
ModelGroupAdapter &ModelDataObjectAdapter::get_group_adapter()
{
   return *group_adapter;
}
ModelShooterAdapter &ModelDataObjectAdapter::get_shooter_adapter()
{
   return *shooter_adapter;
}
ModelParticleTemplateAdapter &ModelDataObjectAdapter::get_particle_template_adapter()
{
   return *particle_template_adapter;
}
ModelEmitterTemplateAdapter &ModelDataObjectAdapter::get_emitter_template_adapter()
{
   return *emitter_template_adapter;
}
ModelDataObjectAdapter *ModelDataObjectAdapter::get_adapter(unsigned int type)
{
   switch(type) {
      case type_group_adapter: return group_adapter;
      case type_shooter_adapter: return shooter_adapter;
      case type_particle_template_adapter: return particle_template_adapter;
      case type_emitter_template_adapter: return emitter_template_adapter;
      default: return 0;
   }
   return 0;
}
ModelDataObjectAdapter *ModelDataObjectAdapter::get_adapter(const QString &class_name)
{
   return get_adapter(get_type(class_name));
}
ModelDataObjectAdapter::ModelDataObjectAdapter()
{
}
ModelDataObjectAdapter::~ModelDataObjectAdapter()
{
}
unsigned int ModelDataObjectAdapter::get_type(const QString &class_name)
{
   if(name_to_type.empty())
   {
      initialize_name_to_type();
   }
   return name_to_type.value(class_name,type_invalid);
}
//
ModelDataObjectAdapter::Initializer ModelDataObjectAdapter::initializer;
QHash<QString,unsigned int> ModelDataObjectAdapter::name_to_type;
